//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.Model.StorageWriters {
        internal class TextStorageWriter : Eas.WebCrawler.Common.BaseDisposable, StorageWriter {
        System.IO.TextWriter _Writer;
        public TextStorageWriter(){}
        protected override void Dispose(bool isDisposing) {
            try {
                if (isDisposing) {
                    if (_Writer != null) {
                        _Writer.Dispose();
                        _Writer = null;
                    }
                }
            }
            finally {
                base.Dispose(isDisposing);
            }
        }

        #region StorageWriter Members

        public void Initialize(Eas.WebCrawler.Interfaces.TemporaryStorage storage) {
            _Writer = storage.GetTextWriter();
        }

        public void Add(byte[] buffer, int count) {
            _Writer.Write(System.Text.Encoding.ASCII.GetChars(buffer, 0, count));
        }

        #endregion

    }
}
